package be.webchess.www.actions;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import org.apache.catalina.util.StringParser;

import be.webchess.www.logic.impl.ChessGameLogic;
import be.webchess.www.model.ChessBoard;
import be.webchess.www.model.ChessPiece;
import be.webchess.www.service.IChessBoardService;
import be.webchess.www.service.IChessPieceService;
import be.webchess.www.service.impl.ChessBoardService;
import be.webchess.www.service.impl.ChessPieceService;

import com.opensymphony.xwork2.ActionSupport;

public class SGameChessAction extends BaseAction {
	
	ChessBoard chess;
	ChessGameLogic	logic;
	IChessBoardService		cbs;
	IChessPieceService		cps;

	/**
	 * 
	 */
	private static final long serialVersionUID = -7529903691398234062L;
	
	public SGameChessAction() {
		// TODO Auto-generated constructor stub
		
	}
	
	public String execute ()
	{
		try {
			cbs = new ChessBoardService(connection);
			cps = new ChessPieceService(connection);
			chess = cbs.findByID(1L);
			logic = new ChessGameLogic(chess);
			
/*			logic.createIntialMatrix();
			
			List<ChessPiece>	pieces = chess.getPieces();
			
			for ( ChessPiece p : pieces )
				cps.insert(p);*/

		} catch ( Exception ex )
		{
			this.addActionError(ex.getMessage());
			return ERROR;
		}
				
		return SUCCESS;
	}

	public Map<String, ChessPiece> getPosition() {
		return logic.getChessBoardMatrix();
	}

	public Long		getChessboardID()
	{
		return chess.getId();
	}
	
	public String	getCurrentPlayerColor()
	{
		return logic.getCurrentPlayerColor();
	}
	
	@Override
	public String getTitle() {
		// TODO Auto-generated method stub
		return "ChessBoard";
	}

	@Override
	public String getContent() {
		// TODO Auto-generated method stub
		return "/WEB-INF/jsp/chessgame.jsp";
	}

	@Override
	public String getErrorTitle() {
		// TODO Auto-generated method stub
		return "GAMECHESS ERROR";
	}

	@Override
	public String getHeadExtra() {
		// TODO Auto-generated method stub
		return "/WEB-INF/jsp/chessgame_scripts.jsp";
	}
	

	
	
	
	
	
	

}
